<template>
    <div><br>
    <el-form v-model="docAd" label-width="80px">
        <el-form-item label="病人名字">
            <el-input :value="patient.name"></el-input>
        </el-form-item>
        <el-form-item label="主治医生">
            <el-input :value="doctor.docName"></el-input>
        </el-form-item>
        <el-form-item label="医嘱内容">
            <el-input type="textarea" v-model="docAd.doContent"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="warning" size="mini" @click="dialogVisible=false">重置</el-button>
            <el-button type="primary" size="mini" @click="addDocAd">确定</el-button>
        </el-form-item>
    </el-form>
    <span style="color: red;">{{ msg }}</span>
    </div>
</template>

<script>
export default {
    props: {
         caseId:{
             type: Number,
             required: true
         }
     },
    data(){
        return{
            docAd:{},//医嘱
            patient:{},
            doctor:{},
            msg:''
        }
    },
    methods:{
        //查找医生信息
        queryDoctor(){
         this.$axios.get("api/doctor/queryDoctor")
         .then(res=>{
             if(res.data.code==200){
                 this.doctor=res.data.data;
             }
         })
         },
         //查找病人信息
         queryPatient(){
             this.$axios.get("api/doctor/queryPatient/"+this.caseId)
             .then(res=>{
             if(res.data.code==200){
                 this.patient=res.data.data;
                 console.log(this.patient)
             }
         }) 
         },
         //添加手术申请
         addDocAd(){
            if(this.docAd.doContent==null || this.docAd.doContent=='' ){
                this.msg="请输入医嘱内容"
                return;
            }
            this.docAd.doCaseId=this.patient.id;
            this.docAd.doWorkerId=this.doctor.id;
            this.$axios.post("api/doctoradvice/addDocAd",this.docAd)
             .then(res=>{
             if(res.data.code==200){
                 this.$message.success("您已发布医嘱")
                 this.closeDialogWithData()
             }
         }) 
         },
         closeDialogWithData() {
             // 触发事件并传递数据给父组件
             this.$emit('closeDialog',this.patient.id); // 替换 dataToPass 为你想要传递的数据
         },
    },
    created(){},
    mounted(){
        this.queryDoctor()
        this.queryPatient()
    }
}
</script>

<style>

</style>